import tornado.web
import tornado.ioloop
import tornado.httpclient
from . import utils
import json
import threading
'''
#1.2声纹串比对接口
    http://ip:port/receive/comparemodel
    {
        "sampleModel":"",
        "targetModel":""
    }
    resp:
    {
        "state":{
            "ok":1,
            "failed":""
        },
        "result":0.99
    }
'''
class receive_comparemodel(tornado.web.RequestHandler):

    def post(self, *args, **kwargs):
        resp = None
        try:
            data=json.loads(self.request.body)
            print(data)
            paramerror = utils.checkParam(data,{
                "sampleModel":"",
                "targetModel":""
            })
            if paramerror == '': #ok
                resp = {
                    "state":{
                        "ok":1,
                        "failed": ""
                    },
                    "result":0.99
                }
            else: #failed
                resp = {
                    "state":{
                        "ok":0,
                        "failed": paramerror
                    },
                    "result":0
                }

        except BaseException as e:
            resp = {
                "state":{
                    "ok":0,
                    "failed": str(e)
                },
                "result":0
            }

        self.write(resp)
